// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import CM from "../../lib/cache/CM";
import { monitor } from "../../lib/common/Decorator";
import UINode from "../../lib/ui/UINode";
import DBattle from "../cache/DBattle";
import DUser from "../cache/DUser";

const {ccclass, property} = cc._decorator;

@ccclass
export default class UIGame extends UINode {
    protected prefab(): string {
        return "prefab/ui/UIGame";
    }

    protected onEvtShow(): void {
        // this.related("label_coin", "DUser", "coin");
        
        // this.related("node_level", "DBattle", "score");

        
        
    }
    @monitor("DUser/coin")
    on_coin_change(attrName, oldVal, newVal) {
        this["label_coin"].getComponent(cc.Label).string = newVal;
    }
    @monitor("DUser/score")
    on_score_change(attrName, oldVal, newVal) {
        for (let i = 1; i <= 3; i++) {
            let star = this["node_level"].getChildByName("star"+i);
            star.getChildByName("light").active = (i <= (newVal));
        }
    }
}
